package org.xq.shop.maxaishop.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xq.shop.maxaishop.entity.XqAddress;
import org.xq.shop.maxaishop.service.XqAddressService;
import org.xq.shop.maxaishop.util.JsonRes;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (XqAddress)表控制层
 *
 * @author makejava
 * @since 2021-06-17 19:55:11
 */
@Api( tags = "用户收货地址管理")
@RestController
@RequestMapping("xqAddress")
public class XqAddressController {
    /**
     * 服务对象
     */
    @Resource
    private XqAddressService xqAddressService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("根据主键查询单个系统用户")
    @ApiImplicitParam(name = "id", value = "地址id", required=true,paramType="query" )
    @GetMapping("selectOne")
    public XqAddress selectOne(Integer id) {
        return this.xqAddressService.queryById(id);
    }

    /**
     * 添加收货地址
     * @return
     */
    @ApiOperation("这是用户添加收货地址的接口")
    @PostMapping("insert")
    public Map insert(XqAddress xqAddress){
        int count = this.xqAddressService.selectCount(xqAddress.getCustomerId());
        if (count>=3){
            return JsonRes.failure(null);
        }else {
            int insert = this.xqAddressService.insert(xqAddress);
            return JsonRes.success(insert);
        }

    }

    /**
     * 查询该用户的地址信息
     * @param uid
     * @return
     */

    @ApiOperation("这是展示用户收货地址接口")
    @ApiImplicitParam(name = "uid", value = "用户ID", required=true,paramType="query" )
    @GetMapping("queryByUId")
    public List<XqAddress> queryByUId(Integer uid){
      return   this.xqAddressService.queryByUId(uid);
    }

    /***
     * 删除指定地址信息
     * @param aid
     * @return
     */
    @ApiOperation("这是删除用户收货地址接口")
    @ApiImplicitParam(name = "aid", value = "地址id", required=true,paramType="query" )
    @GetMapping("deleteById")
    public boolean deleteById(Integer aid){
       return  this.xqAddressService.deleteById(aid);

    }

}
